<template>
  <a-modal
    style="width: 50%"
    title="人脸分发到设备"
    :visible="visible"
    :confirm-loading="confirmLoading"
    :destroyOnClose="true"
    @cancel="handleCancel"
    width="750px"
    :maskClosable="false">
    <div style="margin-top: 12px;">
      <a-form-model ref="ruleAddForm" :model="addForm" :rules="addRules">
        <a-form-model-item label="设备名称" prop="deviceName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入设备名称" v-model="addForm.deviceName" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="设备生产标识" prop="deviceIdentifier" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入设备生产标识" v-model="addForm.deviceIdentifier" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="品牌" prop="brand" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入品牌" v-model="addForm.brand" ></a-input>
        </a-form-model-item>
        <a-form-model-item label="制造商" prop="manufacturer" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input placeholder="请输入制造商" v-model="addForm.manufacturer" ></a-input>
        </a-form-model-item>
      </a-form-model>
    </div>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">
        关闭
      </a-button>
      <a-button type="primary" :visible="visibleBtn" :loading="loadingBtn" @click="handleOk">
        保存
      </a-button>
    </template>
  </a-modal>
</template>
<script>
import { PersonFacesDispatcher } from '@/api/clockingIn'
export default {
    data () {
        return {
            addRules: {
                deviceName: [
                    { required: true, message: '请输入设备名称!', trigger: 'blur' }
                ]
            },
            addForm: {
                deviceId: '', // 设备ID
                facesluiceId: '', // 人脸识别设备云ID
                deviceCustomerId: '',	// 人脸识别设备customer_id
                devicePersonId: '', // 人脸识别设备person_id
                devicePersonName: ''	// 人脸识别设备person_name

            },
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 }
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 }
            },
            disable: true,
            visible: false,
            confirmLoading: false,
            loading: false,
            visibleBtn: false,
            loadingBtn: false
            // mode: "add",
            // titleMap: {
            //     add: '新增',
            //     edit: '编辑'
            // },
            // rowData: null
        }
    },
    methods: {
        // 显示
        open () {
            this.mode = mode
            this.visible = true
            return this
        },

        // 关闭
        handleCancel () {
            this.visible = false
            this.loadingBtn = false
            this.visibleBtn = false
            this.$emit('success')
        },
        // 确认
        handleOk () {
            this.loadingBtn = true
            this.visibleBtn = true
            this.$refs.ruleAddForm.validate(valid => {
                if (valid) {
                    // let Api = this.mode == 'add' ? addPersonFaces : editOrg
                    PersonFacesDispatcher(this.addForm).then(res => {
                        console.log(res)
                        if (res.code === 200) {
                            this.$notification['success']({
                                message: '提示',
                                description: '保存成功！',
                                duration: 8
                            })
                            this.$emit('success')
                            this.visible = false
                        } else {
                            this.$notification['error']({
                                message: '提示',
                                description: res.message,
                                duration: 8
                            })
                        }
                        this.visibleBtn = false
                        this.loadingBtn = false
                    })
                } else {
                    this.loadingBtn = false
                    this.visibleBtn = false
                    return false
                }
            })
        }
    }
}
</script>
<style scoped lang="less" ></style>
